var express = require("express");
const { carRegisterModel } = require("../../model/model");
var router = express.Router();

router.get("/carRegister", async (req, res) => {
  let { name, phone, code, catmark, time, type } = req.query;
  let SearchValue = [{}];
  if (name) SearchValue.push({ name: RegExp(name) });
  let list = await carRegisterModel.find();
  res.send({
    code: 200,
    list: list,
    msg: "查询成功",
  });
});

router.post('/addRegister',(req,res)=>{
  let obj = req.body;
  carRegisterModel.create(obj);
  console.log(obj);
  res.send({
    code:200,
    msg:'添加成功'
  })
});

router.delete('/deleteRegister',async (req,res)=>{
  let id = req.query.id;
  await carRegisterModel.deleteOne({_id:id});
  res.send({
    code:200,
    msg:'删除成功'
  })
})

module.exports = router;
